<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>Cropper</title>
  <link rel="stylesheet" href="../dist/cropper.css">
  <style>
    .container {
      max-width: 960px;
      margin: 20px auto;
    }

    img {
      max-width: 100%;
    }

    .row,
    .preview {
      overflow: hidden;
    }

    .col {
      float: left;
    }

    .col-6 {
      width: 50%;
    }

    .col-3 {
      width: 25%;
    }

    .col-2 {
      width: 16.7%;
    }

    .col-1 {
      width: 8.3%;
    }
  </style>
</head>
<body>

  <div class="container">
    <h1>Customize preview for Cropper</h1>
    <h3>Cropper</h3>
    <div class="row">
      <div class="col col-6">
        <img id="image" src="../docs/images/picture.jpg" alt="Picture">
      </div>
      <div class="col col-3">
        <div class="preview"></div>
      </div>
      <div class="col col-2">
        <div class="preview"></div>
      </div>
      <div class="col col-1">
        <div class="preview"></div>
      </div>
    </div>
  </div>

  <!-- Scripts -->
  <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
  <script src="../dist/cropper.js"></script>
  <script>
    $(function () {
      var $previews = $('.preview');

      $('#image').cropper({
          ready: function (e) {
            var $clone = $(this).clone().removeClass('cropper-hidden');

            $clone.css({
              display: 'block',
              width: '100%',
              minWidth: 0,
              minHeight: 0,
              maxWidth: 'none',
              maxHeight: 'none'
            });

            $previews.css({
              width: '100%',
              overflow: 'hidden'
            }).html($clone);
          },

          crop: function (e) {
            var imageData = $(this).cropper('getImageData');
            var previewAspectRatio = e.width / e.height;

            $previews.each(function () {
              var $preview = $(this);
              var previewWidth = $preview.width();
              var previewHeight = previewWidth / previewAspectRatio;
              var imageScaledRatio = e.width / previewWidth;

              $preview.height(previewHeight).find('img').css({
                width: imageData.naturalWidth / imageScaledRatio,
                height: imageData.naturalHeight / imageScaledRatio,
                marginLeft: -e.x / imageScaledRatio,
                marginTop: -e.y / imageScaledRatio
              });
            });
          }
        });
    });
  </script>
</body>
</html>
